package com.cjkj.agent.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.cjkj.common.annotation.RepeatSubmit;
import org.springframework.security.access.prepost.PreAuthorize;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cjkj.common.annotation.Log;
import com.cjkj.common.core.controller.BaseController;
import com.cjkj.common.core.domain.AjaxResult;
import com.cjkj.common.enums.BusinessType;
import com.cjkj.agent.domain.TAgentInfo;
import com.cjkj.agent.service.ITAgentInfoService;
import com.cjkj.common.utils.poi.ExcelUtil;
import com.cjkj.common.core.page.TableDataInfo;

/**
 * 代理商信息Controller
 * 
 * @author cjkj
 * @date 2025-10-11
 */
@RestController
@RequestMapping("/agent/info")
public class TAgentInfoController extends BaseController
{
    @Resource
    private ITAgentInfoService tAgentInfoService;

    /**
     * 查询代理商信息列表
     */
    @PreAuthorize("@ss.hasPermi('agent:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(TAgentInfo tAgentInfo)
    {
        startPage();
        List<TAgentInfo> list = tAgentInfoService.selectTAgentInfoList(tAgentInfo);
        return getDataTable(list);
    }

    /**
     * 导出代理商信息列表
     */
    @PreAuthorize("@ss.hasPermi('agent:info:export')")
    @Log(title = "代理商信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TAgentInfo tAgentInfo)
    {
        List<TAgentInfo> list = tAgentInfoService.selectTAgentInfoList(tAgentInfo);
        ExcelUtil<TAgentInfo> util = new ExcelUtil<TAgentInfo>(TAgentInfo.class);
        util.exportExcel(response, list, "代理商信息数据");
    }

    /**
     * 获取代理商信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('agent:info:query')")
    @GetMapping(value = "/{agentId}")
    public AjaxResult getInfo(@PathVariable("agentId") String agentId)
    {
        return success(tAgentInfoService.selectTAgentInfoByAgentId(agentId));
    }

    /**
     * 新增代理商信息
     */
    @PreAuthorize("@ss.hasPermi('agent:info:add')")
    @Log(title = "代理商信息", businessType = BusinessType.INSERT)
    @RepeatSubmit(interval = 1000, message = "请求过于频繁！")
    @PostMapping
    public AjaxResult add(@RequestBody TAgentInfo tAgentInfo)
    {
        return toAjax(tAgentInfoService.insertTAgentInfo(tAgentInfo));
    }

    /**
     * 修改代理商信息
     */
    @PreAuthorize("@ss.hasPermi('agent:info:edit')")
    @Log(title = "代理商信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit(interval = 1000, message = "请求过于频繁！")
    @PutMapping
    public AjaxResult edit(@RequestBody TAgentInfo tAgentInfo)
    {
        return toAjax(tAgentInfoService.updateTAgentInfo(tAgentInfo));
    }

    /**
     * 删除代理商信息
     */
    @PreAuthorize("@ss.hasPermi('agent:info:remove')")
    @Log(title = "代理商信息", businessType = BusinessType.DELETE)
    @RepeatSubmit(interval = 1000, message = "请求过于频繁！")
	@DeleteMapping("/{agentIds}")
    public AjaxResult remove(@PathVariable String[] agentIds)
    {
        return toAjax(tAgentInfoService.deleteTAgentInfoByAgentIds(agentIds));
    }

    /**
     * 获取代理商信息下拉框数据
     */
    @GetMapping("/getOptionData")
    public AjaxResult getOptionData(){
        return AjaxResult.success(tAgentInfoService.getOptionData());
    }
}
